package com.ruoyi.service.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.service.domain.ServiceServed;
import com.ruoyi.service.service.IServiceServedService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 被服务人信息Controller
 * 
 * @author ZDL
 * @date 2024-11-27
 */
@RestController
@RequestMapping("/service/served")
public class ServiceServedController extends BaseController
{
    @Autowired
    private IServiceServedService serviceServedService;

    /**
     * 查询被服务人信息列表
     */
    @PreAuthorize("@ss.hasPermi('service:served:list')")
    @GetMapping("/list")
    public TableDataInfo list(ServiceServed serviceServed)
    {
        startPage();
        List<ServiceServed> list = serviceServedService.selectServiceServedList(serviceServed);
        return getDataTable(list);
    }

    /**
     * 导出被服务人信息列表
     */
    @PreAuthorize("@ss.hasPermi('service:served:export')")
    @Log(title = "被服务人信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ServiceServed serviceServed)
    {
        List<ServiceServed> list = serviceServedService.selectServiceServedList(serviceServed);
        ExcelUtil<ServiceServed> util = new ExcelUtil<ServiceServed>(ServiceServed.class);
        util.exportExcel(response, list, "被服务人信息数据");
    }

    /**
     * 获取被服务人信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('service:served:query')")
    @GetMapping(value = "/{servedId}")
    public AjaxResult getInfo(@PathVariable("servedId") Long servedId)
    {
        return success(serviceServedService.selectServiceServedByServedId(servedId));
    }

    /**
     * 新增被服务人信息
     */
    @PreAuthorize("@ss.hasPermi('service:served:add')")
    @Log(title = "被服务人信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ServiceServed serviceServed)
    {
        return toAjax(serviceServedService.insertServiceServed(serviceServed));
    }

    /**
     * 修改被服务人信息
     */
    @PreAuthorize("@ss.hasPermi('service:served:edit')")
    @Log(title = "被服务人信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ServiceServed serviceServed)
    {
        return toAjax(serviceServedService.updateServiceServed(serviceServed));
    }

    /**
     * 删除被服务人信息
     */
    @PreAuthorize("@ss.hasPermi('service:served:remove')")
    @Log(title = "被服务人信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{servedIds}")
    public AjaxResult remove(@PathVariable Long[] servedIds)
    {
        return toAjax(serviceServedService.deleteServiceServedByServedIds(servedIds));
    }
}
